<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the default value's constant name if default value is constant or null</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="reflectionparameter.getdefaultvalue.html">« ReflectionParameter::getDefaultValue</a></li>
      <li style="float: right;"><a href="reflectionparameter.getname.html">ReflectionParameter::getName »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.reflectionparameter.html">ReflectionParameter</a></li>
    <li>Returns the default value's constant name if default value is constant or null</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="reflectionparameter.getdefaultvalueconstantname" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionParameter::getDefaultValueConstantName</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.6, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionParameter::getDefaultValueConstantName</span> &mdash; <span class="dc-title">Returns the default value&#039;s constant name if default value is constant or null</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionparameter.getdefaultvalueconstantname-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionParameter::getDefaultValueConstantName</strong></span>(): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   Returns the default value&#039;s constant name of the parameter of any user-defined
   or internal function or method, if default value is constant or null.
   If the parameter is not optional a <span class="classname"><a href="class.reflectionexception.html" class="classname">ReflectionException</a></span>
   will be thrown.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionparameter.getdefaultvalueconstantname-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionparameter.getdefaultvalueconstantname-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns string on success or <strong><code>null</code></strong> on failure.
  </p>
 </div>


  <div class="refsect1 changelog" id="refsect1-reflectionparameter.getdefaultvalueconstantname-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        This method now allows getting the default values&#039; constant names of built-in functions and
        built-in class methods. Previously, a <span class="classname"><a href="class.reflectionexception.html" class="classname">ReflectionException</a></span> was thrown.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionparameter.getdefaultvalueconstantname-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5235">
    <p><strong>示例 #1 Getting default values&#039; constant names of function parameters</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">(</span><span style="color: #0000BB">$test</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">PHP_INT_MIN</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$test&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bar</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$function&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$function</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParameters</span><span style="color: #007700">()&nbsp;as&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Name:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isOptional</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Default&nbsp;value:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDefaultValueConstantName</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Name: test

Name: bar
Default value: PHP_INT_MIN
</pre></div>
   </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-reflectionparameter.getdefaultvalueconstantname-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="reflectionparameter.isoptional.html" class="methodname" rel="rdfs-seeAlso">ReflectionParameter::isOptional()</a> - Checks if optional</span></li>
    <li class="member"><span class="methodname"><a href="reflectionparameter.isdefaultvalueconstant.html" class="methodname" rel="rdfs-seeAlso">ReflectionParameter::isDefaultValueConstant()</a> - Returns whether the default value of this parameter is a constant</span></li>
    <li class="member"><span class="methodname"><a href="reflectionparameter.getdefaultvalue.html" class="methodname" rel="rdfs-seeAlso">ReflectionParameter::getDefaultValue()</a> - Gets default parameter value</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>